home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d2 / nansi286.arc / NANSI_I.ASM < prev    next >
Assembly Source File  |  1987-07-19  |  3KB  |  111 lines

  1. ;------ nansi_i.asm ----------------------------------------------
  2. ; Contains code only needed at initialization time.
  3. ; (C) 1986 Daniel Kegel
  4. ; May be distributed for educational and personal use only
  5. ;-----------------------------------------------------------------
  6.  
  7.     include nansi_d.asm        ; definitions
  8.  
  9.     ; to nansi.asm
  10.     public    dosfn0
  11.  
  12.     ; from nansi.asm
  13.     extrn    break_handler:near
  14.     extrn    int_29:near
  15.     if    takeBIOS
  16.     extrn    new_vid_bios:near
  17.     extrn    old_vid_bios:dword
  18.     endif
  19.     extrn    req_ptr:dword
  20.     extrn    xlate_tab_ptr:word
  21.  
  22.     ; from nansi_p.asm
  23.     extrn    param_buffer:word    ; adr of first byte free for params
  24.     extrn    param_end:word        ; adr of last byte used for params
  25.     extrn    redef_end:word        ; adr of last used byte for redefs
  26.  
  27.  
  28. code    segment byte public 'CODE'
  29.     assume    cs:code, ds:code
  30.  
  31. ;-------- dos function # 0 : init driver ---------------------
  32. ; Initializes device driver interrupts and buffers, then
  33. ; passes ending address of the device driver to DOS.
  34. ; Since this code is only used once, the buffer can be set up on top
  35. ; of it to save RAM.
  36.  
  37. dosfn0    proc    near
  38.     ; Install BIOS keyboard break handler.
  39.     xor    ax, ax
  40.     mov    ds, ax
  41.     mov    bx, 6Ch
  42.     mov    word ptr [BX],offset break_handler
  43.     mov    [BX+02], cs
  44.     ; Install INT 29 quick putchar.
  45.     mov    bx, 0a4h
  46.     mov    word ptr [bx], offset int_29
  47.     mov    [bx+2], cs
  48.     if    takeBIOS
  49.     ; Install INT 10h video bios replacement.
  50.     mov    bx, 40h
  51.     mov    ax, [bx]
  52.     mov    word ptr cs:old_vid_bios, ax
  53.     mov    ax, [bx+2]
  54.     mov    word ptr cs:old_vid_bios[2], ax
  55.     mov    word ptr [bx], offset new_vid_bios
  56.     mov    word ptr [bx+2], cs
  57.     endif
  58.  
  59.     push    cs
  60.     pop    ds
  61.     push    cs
  62.     pop    es            ; es=cs so we can use stosb
  63.     cld                ; make sure stosb increments di
  64.  
  65.     ; Calculate addresses of start and end of parameter/redef buffer.
  66.     ; The buffer occupies the same area of memory as this code!
  67.     ; ANSI parameters are accumulated at the lower end, and
  68.     ; keyboard redefinitions are stored at the upper end; the variable
  69.     ; param_end is the last byte used by params (changes as redefs added);
  70.     ; redef_end is the last word used by redefinitions.
  71.     mov    di, offset dosfn0
  72.     mov    param_buffer, di
  73.     add    di, 512
  74.     mov    param_end, di    ; addr of last byte in free area
  75.     inc    di
  76.  
  77.     ; Build the default redefinition table:
  78.     ;    control-printscreen -> control-P
  79.     ; (Must be careful not to write over ourselves here!)
  80.     mov    al, 16        ; control P
  81.     stosb
  82.     mov    ax, 7200h    ; control-printscreen
  83.     stosw
  84.     mov    ax, 1        ; length field
  85.     mov    redef_end, di    ; address of last used word in table
  86.     stosw
  87.  
  88.     ; Build a 1:1 output character translation table.
  89.     ; It is 256 bytes long, starts just after the param/redef buffer,
  90.     ; and is the last thing in the initialized device driver.
  91.     mov    xlate_tab_ptr, di
  92.     xor    ax, ax
  93. init_loop:
  94.     stosb
  95.     inc    al
  96.     jnz    init_loop
  97.  
  98.     xor    ax, ax
  99.     ; Return ending address of this device driver.
  100.     ; Status is in AX.
  101.     lds    si, req_ptr
  102.     mov    word ptr [si+0Eh], di
  103.     mov    [si+10h], cs
  104.     ; Return exit status in ax.
  105.     ret
  106.  
  107. dosfn0    endp
  108.  
  109. code    ends
  110.     end                ; of nansi_i.asm
  111.